package com.example.leetcode.geometry.common;

public class GeometryUtils {

    /**
     * 将二维矩形重叠转换为一维区间重叠问题
     * 当x和y方向都重叠时，矩形存在重叠
     *
     * @param rec1
     * @param rec2
     * @return
     */
    public static boolean isRectangleOverlap(int[] rec1, int[] rec2) {
        boolean x_overlap = !(rec1[2] <= rec2[0] || rec2[2] <= rec1[0]);
        boolean y_overlap = !(rec1[3] <= rec2[1] || rec2[3] <= rec1[1]);
        return x_overlap && y_overlap;
    }
}
